package com.easyCode.feature.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author 大忽悠
 * @create 2022/9/23 22:04
 */
@Slf4j
@Configuration
@ConditionalOnClass({ExceptionHandler.class,DuplicateKeyException.class})
@ConditionalOnProperty(prefix = "easy-generator.global.feature",name= "exception",havingValue = "true",matchIfMissing = true)
public class ExceptionAutoConfiguration {

    @ConditionalOnMissingBean(WebExceptionHandler.class)
    @Bean
    public WebExceptionHandler webExceptionHandler(){
        log.info("webExceptionHandler配置成功!");
        return new WebExceptionHandler();
    }
}
